import 'package:finance_app/src/entities/company_entity.dart';

companyEntityFromJson(CompanyEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['uen'] != null) {
		data.uen = json['uen'].toString();
	}
	if (json['country'] != null) {
		data.country = json['country'].toString();
	}
	if (json['email'] != null) {
		data.email = json['email'].toString();
	}
	if (json['website'] != null) {
		data.website = json['website'].toString();
	}
	if (json['logo'] != null) {
		data.logo = json['logo'];
	}
	if (json['business_type'] != null) {
		data.businessType = json['business_type'].toString();
	}
	if (json['industry_type'] != null) {
		data.industryType = json['industry_type'].toString();
	}
	if (json['country_code'] != null) {
		data.countryCode = json['country_code'].toString();
	}
	if (json['phone_number'] != null) {
		data.phoneNumber = json['phone_number'];
	}
	if (json['address_country'] != null) {
		data.addressCountry = json['address_country'].toString();
	}
	if (json['address_city'] != null) {
		data.addressCity = json['address_city'].toString();
	}
	if (json['address_postal_code'] != null) {
		data.addressPostalCode = json['address_postal_code'].toString();
	}
	if (json['address_line_1'] != null) {
		data.addressLine1 = json['address_line_1'].toString();
	}
	if (json['address_line_2'] != null) {
		data.addressLine2 = json['address_line_2'];
	}
	if (json['address_unit'] != null) {
		data.addressUnit = json['address_unit'].toString();
	}
	if (json['delivery_address_country'] != null) {
		data.deliveryAddressCountry = json['delivery_address_country'].toString();
	}
	if (json['delivery_address_city'] != null) {
		data.deliveryAddressCity = json['delivery_address_city'].toString();
	}
	if (json['delivery_address_postal_code'] != null) {
		data.deliveryAddressPostalCode = json['delivery_address_postal_code'].toString();
	}
	if (json['delivery_address_line_1'] != null) {
		data.deliveryAddressLine1 = json['delivery_address_line_1'].toString();
	}
	if (json['delivery_address_line_2'] != null) {
		data.deliveryAddressLine2 = json['delivery_address_line_2'];
	}
	if (json['delivery_address_unit'] != null) {
		data.deliveryAddressUnit = json['delivery_address_unit'].toString();
	}
	if (json['financial_year_start_at'] != null) {
		data.financialYearStartAt = json['financial_year_start_at'];
	}
	if (json['financial_year_end_at'] != null) {
		data.financialYearEndAt = json['financial_year_end_at'];
	}
	if (json['financial_year_period'] != null) {
		data.financialYearPeriod = json['financial_year_period'] is String
				? int.tryParse(json['financial_year_period'])
				: json['financial_year_period'].toInt();
	}
	if (json['enable_gst'] != null) {
		data.enableGst = json['enable_gst'] is String
				? int.tryParse(json['enable_gst'])
				: json['enable_gst'].toInt();
	}
	if (json['gst_agency'] != null) {
		data.gstAgency = json['gst_agency'].toString();
	}
	if (json['gst_agency_text'] != null) {
		data.gstAgencyText = json['gst_agency_text'].toString();
	}
	if (json['gst_number'] != null) {
		data.gstNumber = json['gst_number'];
	}
	if (json['filling_frequency'] != null) {
		data.fillingFrequency = json['filling_frequency'].toString();
	}
	if (json['filling_frequency_text'] != null) {
		data.fillingFrequencyText = json['filling_frequency_text'].toString();
	}
	if (json['gst_effective_date'] != null) {
		data.gstEffectiveDate = json['gst_effective_date'].toString();
	}
	if (json['gst_rate'] != null) {
		data.gstRate = json['gst_rate'].toString();
	}
	if (json['default_currency_code'] != null) {
		data.defaultCurrencyCode = json['default_currency_code'].toString();
	}
	if (json['default_payment_type_id'] != null) {
		data.defaultPaymentTypeId = json['default_payment_type_id'];
	}
	if (json['date_format'] != null) {
		data.dateFormat = json['date_format'].toString();
	}
	if (json['templates'] != null) {
		data.templates = CompanyTemplates().fromJson(json['templates']);
	}
	if (json['currencies'] != null) {
		data.currencies = json['currencies'];
	}
	if (json['contributions'] != null) {
		data.contributions = json['contributions'];
	}
	if (json['my_role'] != null) {
		data.myRole = json['my_role'].toString();
	}
	if (json['created_by'] != null) {
		data.createdBy = json['created_by'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	return data;
}

Map<String, dynamic> companyEntityToJson(CompanyEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['name'] = entity.name;
	data['uen'] = entity.uen;
	data['country'] = entity.country;
	data['email'] = entity.email;
	data['website'] = entity.website;
	data['logo'] = entity.logo;
	data['business_type'] = entity.businessType;
	data['industry_type'] = entity.industryType;
	data['country_code'] = entity.countryCode;
	data['phone_number'] = entity.phoneNumber;
	data['address_country'] = entity.addressCountry;
	data['address_city'] = entity.addressCity;
	data['address_postal_code'] = entity.addressPostalCode;
	data['address_line_1'] = entity.addressLine1;
	data['address_line_2'] = entity.addressLine2;
	data['address_unit'] = entity.addressUnit;
	data['delivery_address_country'] = entity.deliveryAddressCountry;
	data['delivery_address_city'] = entity.deliveryAddressCity;
	data['delivery_address_postal_code'] = entity.deliveryAddressPostalCode;
	data['delivery_address_line_1'] = entity.deliveryAddressLine1;
	data['delivery_address_line_2'] = entity.deliveryAddressLine2;
	data['delivery_address_unit'] = entity.deliveryAddressUnit;
	data['financial_year_start_at'] = entity.financialYearStartAt;
	data['financial_year_end_at'] = entity.financialYearEndAt;
	data['financial_year_period'] = entity.financialYearPeriod;
	data['enable_gst'] = entity.enableGst;
	data['gst_agency'] = entity.gstAgency;
	data['gst_agency_text'] = entity.gstAgencyText;
	data['gst_number'] = entity.gstNumber;
	data['filling_frequency'] = entity.fillingFrequency;
	data['filling_frequency_text'] = entity.fillingFrequencyText;
	data['gst_effective_date'] = entity.gstEffectiveDate;
	data['gst_rate'] = entity.gstRate;
	data['default_currency_code'] = entity.defaultCurrencyCode;
	data['default_payment_type_id'] = entity.defaultPaymentTypeId;
	data['date_format'] = entity.dateFormat;
	data['templates'] = entity.templates?.toJson();
	data['currencies'] = entity.currencies;
	data['contributions'] = entity.contributions;
	data['my_role'] = entity.myRole;
	data['created_by'] = entity.createdBy;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	return data;
}

companyTemplatesFromJson(CompanyTemplates data, Map<String, dynamic> json) {
	if (json['invoice'] != null) {
		data.invoice = json['invoice'].toString();
	}
	if (json['delivery'] != null) {
		data.delivery = json['delivery'].toString();
	}
	if (json['credit_note'] != null) {
		data.creditNote = json['credit_note'].toString();
	}
	if (json['purchase_order'] != null) {
		data.purchaseOrder = json['purchase_order'].toString();
	}
	return data;
}

Map<String, dynamic> companyTemplatesToJson(CompanyTemplates entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['invoice'] = entity.invoice;
	data['delivery'] = entity.delivery;
	data['credit_note'] = entity.creditNote;
	data['purchase_order'] = entity.purchaseOrder;
	return data;
}